<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="com.sh_lianjing.web.el.EL"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<% Boolean isEdit = EL.eval("${moduleType=='Edit'}", Boolean.class, pageContext); %>
<%-- 定义变量 --%>
<c:set var="comment" value="${formInfo.comment}"/>
<c:set var="fieldName" value="${baseFieldName}${formInfo.fieldName}"/>
<c:if test="${formInfo.type!='Img'}">
	<c:set var="value" value='<%=EL.eval("${beanItem!=null}",Boolean.class, pageContext) ? EL.eval("${beanItem."+EL.eval("${formInfo.fieldName}",String.class, pageContext)+"}", pageContext) : EL.eval("${formInfo.defaultValue}", pageContext) %>'/>
</c:if>
<c:set var="isTextarea" value="${formInfo.type=='Text' && formInfo.maxLength>=200}"/>
<c:set var="isInput" value="${formInfo.type=='Text' && formInfo.maxLength<200}"/>
<c:set var="isEditor" value="${formInfo.type=='Editor'}"/>
<c:set var="isGroup" value="${!empty formInfo.group}"/>
<c:if test="${isGroup}">
	<c:set var="groupName" value="${formInfo.group.name}"/>
	<c:set var="groupComment" value="${formInfo.group.comment}"/>
	<c:set var="groupIndex" value="${formInfo.group.index}"/>
	<c:set var="groupLength" value="${formInfo.group.length}"/>
	<c:set var="groupStart" value="${groupIndex==0}"/>
	<c:set var="groupEnd" value="${groupIndex+1==groupLength}"/>
	<c:set var="fieldNameAccess" value="${fieldName}Access"/>
	<c:if test="${!groupStart}">
		<c:set var="disabled" value="disabled='disabled'"/>
	</c:if>
	<c:set var="myCom" value="com='myDataFind'"/>
</c:if>
<c:if test="${formInfo.disabled}">
	<c:set var="disabled" value="disabled='disabled' disabledFlag='true'"/>
</c:if>
<c:if test="${formInfo.hide}">
	<c:set var="hide" value="hidden='hidden'"/>
</c:if>

<% Object value = EL.eval("${value}", pageContext); %>
<c:set var="explain" value="${formInfo.validateCommentsAsString}"/>
<c:set var="notNullable" value="${!formInfo.nullable}"/>

<c:set var="requiredValidate" value="" />
<c:if test="${notNullable}">
	<c:set var="requiredValidate" value="required data-required-error='${formInfo.validateMessages.Required}'"/>
</c:if>
<c:set var="sizeValidate" value="minlength='${formInfo.minLength}' maxlength='${formInfo.maxLength}' data-error='${formInfo.validateMessages.Size}'"/>

<c:set var="redirectInfo" value="" />
<c:if test="${null != formInfo.redirect.url}">
<c:set var="redirectInfo" value="redirect_url='${formInfo.redirect.url}' redirect_withParam='${formInfo.redirect.withParam}' "/>
</c:if>

<%-- 输入框 --%>
<div 
	<c:if test="${isGroup}">groupName="${groupName}"</c:if>
	<c:if test="${!isGroup && !isTextarea && !isEditor}">class="col-lg-3" </c:if>
	<c:if test="${isGroup}">class="xxh_linkage_select" style="float: left;"</c:if>
	<c:if test="${!isGroup && (isTextarea || isEditor)}">class="col-lg-12"</c:if>
	${hide}
>
<div class="form-group has-feedback" com="myValidate" failAfterAction="@fun:fun_validateFail()" successAfterAction="@fun:fun_validateSuccess()" >

 	<%-- 标题 --%>
 	<c:if test="${!isGroup}">
	<label class="control-label" for="${fieldName}">
		<c:if test="${notNullable}"><span style="color:red;">*</span></c:if>${comment}
	</label>
	</c:if>
	
	<%-- S 输入 --%>
		<%-- 普通文本 --%>
		<c:if test="${isInput}">
		<input type="text" id="${fieldName}" class="form-control" name="${fieldName}" value="${value}" ignoreBlank="true" ${disabled} ${hide}
		 data-toggle="tooltip" title="请输入一个${explain}的字符串！" placeholder="请输入${comment}" formType="${formInfo.type}"
		 ${requiredValidate} ${sizeValidate} ${redirectInfo}
		/>
		</c:if>
		
		<%-- textarea文本 --%>
		<c:if test="${isTextarea}">
		<textarea id="${fieldName}" class="form-control" name="${fieldName}" rows="3" ignoreBlank="true"  <%-- ${disabled} --%> 
		 data-toggle="tooltip" title="请输入一个${explain}的字符串！" placeholder="请输入${comment}" formType="Textarea"
		 ${requiredValidate} ${sizeValidate} ${redirectInfo}
		>${value}</textarea>
		</c:if>
		
		<%-- 富文本编辑器 --%>
     	<c:if test="${formInfo.type=='Editor'}">
		<div data-toggle="tooltip" title="请输入一个${explain}的字符串！">
			<textarea height="100" id="${fieldName}" class="form-control" name="${fieldName}" value="<c:out value='${value}'/>" ignoreBlank="true" ${disabled} 
			 com="myEditer" config="@data:editer_config2" run="bind" formType="${formInfo.type}"
			 ${requiredValidate} ${sizeValidate} ${redirectInfo} 
			></textarea>
		</div>
     	</c:if>

		<%-- Email --%>
		<c:if test="${formInfo.type=='Email'}">
		<input type="email" id="${fieldName}" class="form-control" name="${fieldName}" value="${value}" ignoreBlank="true" ${disabled} 
		 data-toggle="tooltip" title="请输入一个${explain}！" placeholder="请输入${comment}" formType="${formInfo.type}"
		 ${requiredValidate} ${sizeValidate} ${redirectInfo}
		 data-type-error="${formInfo.validateMessages.Email}"
		/>
		</c:if>
		
		<%-- 电话 --%>
		<c:if test="${formInfo.type=='Phone'}">
		<input type="text" id="${fieldName}" class="form-control" name="${fieldName}" value="${value}" ignoreBlank="true" ${disabled} 
		 data-toggle="tooltip" title="请输入一个${explain}！" placeholder="请输入${comment}" formType="${formInfo.type}"
		 ${requiredValidate} ${sizeValidate} ${redirectInfo}
		 pattern="${formInfo.match}" data-pattern-error="${formInfo.validateMessages.Phone}"
		/>
		</c:if>

		<%-- 数字 --%>
		<c:if test="${formInfo.type=='NumberInteger'}">
		<input type="number" id="${fieldName}" class="form-control" name="${fieldName}" value="${value}" ignoreBlank="true" ${disabled} 
		 data-toggle="tooltip" title="请输入一个${explain}的数字！" placeholder="请输入${comment}" formType="${formInfo.type}"
		 ${requiredValidate} ${redirectInfo}
		 min="${formInfo.min}" data-min-error="${formInfo.validateMessages.Min}" 
		 max="${formInfo.max}"  data-max-error="${formInfo.validateMessages.Max}"
		/>
		</c:if>
		<c:if test="${formInfo.type=='NumberFloat'}">
		<input id="${fieldName}" class="form-control" name="${fieldName}" value="${value}" ignoreBlank="true" ${disabled} 
		 data-toggle="tooltip" title="请输入一个${explain}的数字！" placeholder="请输入${comment}" formType="${formInfo.type}"
		 ${requiredValidate} ${redirectInfo}
		 min="${formInfo.min}" data-min-error="${formInfo.validateMessages.Min}" 
		 max="${formInfo.max}"  data-max-error="${formInfo.validateMessages.Max}"
		/>
		</c:if>

		<%-- 密码 --%>
		<c:if test="${formInfo.type=='Password'}">
		<input type="password" id="${fieldName}" class="form-control" name="${fieldName}" value="${value}" ignoreBlank="true" ${disabled} 
		 data-toggle="tooltip" title="请输入一个${explain}的字符串！" placeholder="请输入${comment}" formType="${formInfo.type}"
		 ${requiredValidate} ${sizeValidate} ${redirectInfo}
		/>
		</c:if>

		<%-- URL --%>
		<c:if test="${formInfo.type=='URL'}">
		<input type="url" id="${fieldName}" class="form-control" name="${fieldName}" value="${value}" ignoreBlank="true" ${disabled} 
		 data-toggle="tooltip" title="请输入一个${explain}！" placeholder="请输入${comment}" formType="${formInfo.type}"
		 ${requiredValidate} ${sizeValidate} ${redirectInfo}
		 data-type-error="${formInfo.validateMessages.URL}"
		/>
		</c:if>
		
		<%-- 日期 --%>
		<c:if test="${formInfo.type=='Date'}">
		<% 
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
			String dateString = "";
			if(null == value){
				if(!isEdit){ // 添加情况下
					dateString = dateFormat.format(new Date());
				}
			}else if(value instanceof String){
				dateString = dateFormat.format(dateFormat.parse(value.toString()));
			}else if(value instanceof Date){
				dateString = dateFormat.format(value);
			}
		%>
       	<input type="date" id="${fieldName}" class="form-control" name="${fieldName}" value='<%=dateString%>' ignoreBlank="true" ${disabled} 
       	 data-toggle="tooltip" title="请输入一个${explain}！" placeholder="请输入${comment}" formType="${formInfo.type}"
       	 ${requiredValidate} ${redirectInfo}
       	 data-type-error="${formInfo.validateMessages.DateTimeFormat}"
       	/>
		</c:if>
		
		<%-- 枚举类型 --%>
		<c:if test="${formInfo.type=='Enum'}">
		<select id="${fieldName}" class="form-control" name="${fieldName}" ignoreBlank="true" ${disabled} 
		 data-toggle="tooltip" title="请选择！" formType="${formInfo.type}"
		 ${requiredValidate} ${redirectInfo}
		>
			<option value="" >未选择</option>
			<c:forEach items="${formInfo.enums}" var="item">
				<c:if test="${value==item.key}" var="select_flag">
				<option selected="selected" value="${item.key}">${item.value}</option>
				</c:if>
				<c:if test="${!select_flag}">
				<option value="${item.key}">${item.value}</option>
				</c:if>
			</c:forEach>
		</select>
		</c:if>
		
		<%-- 集合类型 --%>
		<c:if test="${formInfo.type=='Multiple'}">
        <div id="${fieldName}" class="form-group" 
         data-toggle="tooltip" title="请选择${explain}！"
         ignoreBlank="true"
        >
			<c:forEach items="${moduleBody.relations[fieldName]}" var="item">
		    <div class=checkbox-inline  >
				<label>
					<input type="checkbox" name="${fieldName}[].id" value="${item.id}" ignoreBlank="true" ${disabled}  formType="${formInfo.type}"
					 ${sizeValidate} ${redirectInfo}
					 <%=(isEdit && null!=EL.eval("${beanItem[fieldName]}", pageContext) && EL.eval("${beanItem[fieldName]}", Collection.class, pageContext).contains(EL.eval("${item}", pageContext))) ? "checked='checked'" : ""%>
					/> ${item}
				</label>
			</div>
            </c:forEach>
		</div>
       	</c:if>
       	
       	<%-- 普通文本 --%>
		<c:if test="${formInfo.type=='Boolean'}">
			<div data-toggle="tooltip" title="请选择！" class="form-group" >
				<label class="radio-inline">
					<input type="radio" name="${fieldName}" id="${fieldName}" value="true" formType="${formInfo.type}"
					 ${requiredValidate} ${redirectInfo} ignoreBlank="true" ${disabled}  <c:if test='${value==true || value=="true"}'>checked="checked"</c:if>
					/> 是
	            </label>
	            <label class="radio-inline">
					<input type="radio" name="${fieldName}" id="${fieldName}" value="false" formType="${formInfo.type}"
					 ${requiredValidate} ${redirectInfo} ignoreBlank="true" ${disabled}  <c:if test='${value==false || value=="false"}'>checked="checked"</c:if>
					/> 否
	            </label>
			</div>
		</c:if>

		<%-- 对象类型 --%>
		<c:if test="${formInfo.type=='Single'}">
			<div <c:if test="${isGroup}"> ${myCom} access="${requestScope[fieldNameAccess]}" bindTargets="$`select" bindEvents="change" bindBeforeAction="@fun:js_fun_select_before()" bindAfterAction="@fun:js_fun_select_after()"</c:if> >
				<div <c:if test="${isGroup && !groupEnd}">com="myFilter"</c:if> >
					<select
					 id="${fieldName}" name="${fieldName}.id" ignoreBlank="true" ${disabled}  formType="${formInfo.type}"
					 <c:if test="${isGroup}">class="form-control js_select_${groupName} js_select_${groupName}_${groupIndex}"</c:if> <c:if test="${!isGroup}">class="form-control"</c:if> 
					 data-toggle="tooltip" title="请选择！" 
					 ${requiredValidate} ${redirectInfo}
					>
						<option value="" >未选择</option>
						<c:forEach items="${moduleBody.relations[fieldName]}" var="item">
							<option <%=(isEdit && EL.eval("${item}", pageContext).equals(EL.eval("${value}", pageContext))) ? "selected='selected'" : ""%> value="${item.id}">${item}</option>
						</c:forEach>
					</select>
					<c:if test="${isGroup}">
						<span> ${comment} </span>
					</c:if>
				</div>

				<c:if test="${isGroup}">
					<script com="myScript" type="text/template" appendTo=".js_select_${groupName}_${groupIndex+1}">
						<option value="" >未选择</option>
						{{for records}}
							<option value="{{:id}}" >{{:name}}</option>
						{{/for}}
					</script>
				</c:if>
			</div>
		</c:if>

	    <%-- 文件类型 --%>
		<c:if test="${formInfo.type=='File'}">
		<input type="file" id="${fieldName}" class="form-control" name="${fieldName}" value="${value}" ignoreBlank="true" ${disabled} 
		 data-toggle="tooltip" title="请添加${explain}的文件！" placeholder="请添加${comment}" formType="${formInfo.type}"
		 ${requiredValidate} ${redirectInfo}
		/>
		</c:if>
		
		<%-- 图片类型 --%>
		<c:if test="${formInfo.type=='Img'}">
		<div data-toggle="tooltip" title="请添加${explain}的图片文件！" >
		<input com="myImg" initAfterAction="@fun:fileuploadConfig()" type="file" id="${fieldName}" class="form-control fileuploadPlus file-loading" name="${fieldName}" show="<%=EL.eval("${beanItem."+EL.eval("${fieldName}",String.class, pageContext).replaceAll("File$", "")+"}", pageContext) %>" ${disabled} 
		 data-allowed-file-extensions='["png", "jpg"]' formType="${formInfo.type}"
		 placeholder="请添加${comment}" 
		 ${requiredValidate} ${redirectInfo}
		/>
		</div>
		</c:if>

		<%-- 图示 --%>
		<span class="glyphicon form-control-feedback"></span>
		<%-- 显示信息 --%>
    	<div class="help-block with-errors"></div>
	<%-- E 输入 --%>
</div>
<!-- E 输入框 -->
</div>